//
//  MainViewController.m
//  新浪微博
//
//  Created by 行者 on 16/3/6.
//  Copyright © 2016年 Apple. All rights reserved.
//

#import "MainViewController.h"
#import "RootViewController.h"
#import "HomeViewController.h"
#import "MessageViewController.h"
#import "DiscoverViewController.h"
#import "ProfileViewController.h"
// 定义一个RGB的颜色
#define HWColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]

@interface MainViewController ()


@end

@implementation MainViewController

/// 1.初始化自控制器，添加到tabbar控制器里面
- (void)viewDidLoad {
    [super viewDidLoad];
    
    HomeViewController *hmVc = [[HomeViewController alloc]init];
    [self addChildVc:hmVc title:@"首页" image:@"tabbar_home" selectedImage:@"tabbar_home_selected"];
    
    MessageViewController *msVc = [[MessageViewController alloc]init];
    [self addChildVc:msVc title:@"消息" image:@"tabbar_message_center" selectedImage:@"tabbar_message_center_selected"];
    
    DiscoverViewController *dsVc = [[DiscoverViewController alloc]init];
    [self addChildVc:dsVc title:@"发现" image:@"tabbar_discover" selectedImage:@"tabbar_discover_selected"];
    
    ProfileViewController *pfVc = [[ProfileViewController alloc]init];
    [self addChildVc:pfVc title:@"我" image:@"tabbar_profile" selectedImage:@"tabbar_profile_selected"];
    
    
}


/// 2.添加一个子控制器,设置子控制器的文字，图片，文字的样式
-(void)addChildVc:(UIViewController *)childVc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage {

    // 设置子控制器的文字
    childVc.title =title;
    
    // 设置子控制器的图片
    childVc.tabBarItem.image = [UIImage imageNamed:image];
    childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    // 设置tabbar文字的颜色
    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSForegroundColorAttributeName] = [UIColor orangeColor];
    
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = HWColor(123, 123, 123);
    
    
    [childVc.tabBarItem setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    [childVc.tabBarItem setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
    
    // 添加为子控制器
    // No visible @interface for 'RootViewController' declares the selector 'initWithRootViewController:'
    [self addChildViewController:childVc];
    
}


@end
